﻿Public Class FormFiltreScript
    Public oColScripts As New ClassColMacros

    Private Sub FormFiltreScript_Shown(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Shown
        'code par défaut
        If Me.TextBox1.Text = "" Then
            Me.TextBox1.Text = "'Remplacer le code ci-dessous par le code désiré" & vbCrLf
            Me.TextBox1.Text = "Texte = uCase(Texte)"
        End If
    End Sub

    Private Sub Button5_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button5.Click
        Dim oTrans As New ClassTextOp
        oTrans.Operation = ClassTextOp.EnumTextOperation.ScriptRemplacement
        oTrans.Parametres(0) = Me.TextBox1.Text
        If Me.RadioButton1.Checked Then
            oTrans.Parametres(1) = "global"
        Else
            oTrans.Parametres(1) = "lignes"
        End If
        'Me.UndoText.Push(Me.RichComboBoxFiltre.Text)
        'Me.Button4.Enabled = True
        'Me.RichComboBoxFiltre.Text = oTrans.Transformer(Me.RichComboBoxFiltre.Text)
        Me.RichTextBoxResult.Text = oTrans.Transformer(Me.RichComboBoxFiltre.Text)
        oTrans = Nothing
    End Sub

    Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
        Call Commun.VBScriptHelp()
    End Sub

  
    Private Sub Button3_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button3.Click
        'Save
        If Me.ComboBox1.Text <> "" Then
            If oColScripts.Contains(Me.ComboBox1.Text) Then
                Dim oScript As ClassMacro = oColScripts.Item(Me.ComboBox1.Text)
                oScript.Code = Me.TextBox1.Text
            Else
                Dim oScript As New ClassMacro
                oScript.Titre = Me.ComboBox1.Text
                oScript.Code = Me.TextBox1.Text
                oColScripts.add(oScript.Titre, oScript)
                Me.ComboBox1.Items.Add(Me.ComboBox1.Text)
            End If
        Else
            MsgBox("Vous devez donner un nom à votre nouvelle Macro", MsgBoxStyle.Exclamation)
        End If
    End Sub

    Private Sub ButtonDel_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles ButtonDel.Click
        'Delete
        If Me.oColScripts.Contains(Me.ComboBox1.Text) Then oColScripts.Remove(Me.ComboBox1.Text)
        If Me.ComboBox1.Items.Contains(Me.ComboBox1.Text) Then
            Me.ComboBox1.Items.Remove(Me.ComboBox1.Text)
            Me.ComboBox1.Text = ""
            Me.TextBox1.Text = ""
        End If
    End Sub

    Private Sub ComboBox1_SelectedIndexChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles ComboBox1.SelectedIndexChanged
        'Select
        If Me.ComboBox1.Text <> "" Then
            If oColScripts.Contains(Me.ComboBox1.Text) Then
                Dim oScript As ClassMacro = oColScripts.Item(Me.ComboBox1.Text)
                Me.TextBox1.Text = oScript.Code
            End If
        End If
    End Sub
End Class